package net.dopan.pigframe.user.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.dopan.pigframe.core.base.controller.BaseController;
import net.dopan.pigframe.core.base.controller.response.ResponseBean;
import net.dopan.pigframe.core.utils.Query;
import net.dopan.pigframe.user.model.entity.SysOauthClientDetails;
import net.dopan.pigframe.user.service.SysOauthClientDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Package: net.dopan.pigframe.user.controller
 * @Title: OauthClientDetailsController
 * @Description: 客户端管理
 * @author: 刘宽
 * @date: 2018/9/2 21:25
 */
@RestController
@RequestMapping("/client")
@Api(tags = "客户端管理接口(API)", description = "客户端管理相关操作")
public class OauthClientDetailsController extends BaseController {

    @Autowired
    private SysOauthClientDetailsService sysOauthClientDetailsService;

    /**
     * 通过ID查询
     *
     * @param id ID
     * @return SysOauthClientDetails
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询", notes = "通过ID查询")
    public SysOauthClientDetails get(@PathVariable Integer id) {
        return sysOauthClientDetailsService.selectById(id);
    }


    /**
     * 分页查询信息
     *
     * @param params 分页对象
     * @return 分页对象
     */
    @RequestMapping("/page")
    @ApiOperation(value = "分页查询信息", notes = "分页查询信息")
    public Page page(@RequestParam Map<String, Object> params) {
        return sysOauthClientDetailsService.selectPage(new Query<>(params), new EntityWrapper<>());
    }

    /**
     * 添加
     *
     * @param sysOauthClientDetails 实体
     * @return success/false
     */
    @PostMapping
    @ApiOperation(value = "添加", notes = "添加")
    public ResponseBean<Boolean> add(@RequestBody SysOauthClientDetails sysOauthClientDetails) {
        return new ResponseBean<>(sysOauthClientDetailsService.insert(sysOauthClientDetails));
    }

    /**
     * 删除
     *
     * @param id ID
     * @return success/false
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除", notes = "删除")
    public ResponseBean<Boolean> delete(@PathVariable String id) {
        SysOauthClientDetails sysOauthClientDetails = new SysOauthClientDetails();
        sysOauthClientDetails.setClientId(id);
        return new ResponseBean<>(sysOauthClientDetailsService.deleteById(sysOauthClientDetails));
    }

    /**
     * 编辑
     *
     * @param sysOauthClientDetails 实体
     * @return success/false
     */
    @PutMapping
    @ApiOperation(value = "编辑", notes = "编辑")
    public ResponseBean<Boolean> edit(@RequestBody SysOauthClientDetails sysOauthClientDetails) {
        return new ResponseBean<>(sysOauthClientDetailsService.updateById(sysOauthClientDetails));
    }
}
